package main

import (
	"gitchina/kly_service/controllers"
	"gitchina/kly_service/data"
	_ "gitchina/kly_service/docs"
	"gitchina/kly_service/filters"
	model "gitchina/kly_service/models"
	_ "gitchina/kly_service/routers"
	"gitchina/kly_service/util"
	"gitchina/kly_service/util/sms"
	"os"

	"github.com/astaxie/beego"
)

func main() {
	runmode := os.Getenv("KLYRUNMODE")
	beego.BConfig.RunMode = runmode
	util.InitLogger(beego.BConfig.RunMode)
	util.InitPush(beego.BConfig.RunMode)
	util.InitJms(beego.BConfig.RunMode)
	model.InitContract("")
	model.InitInsurance(beego.BConfig.RunMode)
	sms.Init(beego.BConfig.RunMode)
	data.InitOrm(beego.BConfig.RunMode)

	if beego.BConfig.RunMode != "prod" {
		beego.BConfig.Log.AccessLogs = true
		beego.BConfig.WebConfig.DirectoryIndex = true
		beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"

	}

	if beego.BConfig.RunMode != "dev" {
		adapter, config := util.GetLoggerProfile()
		beego.BConfig.Log.Outputs = map[string]string{adapter: config}
		beego.LoadAppConfig("ini", "conf/app.conf")
	}

	controllers.Init()

	beego.InsertFilter("/*", beego.BeforeRouter, filters.DebugFilterFunc)
	beego.InsertFilter("/*", beego.BeforeRouter, filters.IPFilterFunc)
	beego.InsertFilter("/*/api/:id*", beego.BeforeRouter, filters.VersionFilterFunc)
	beego.InsertFilter("/*/api/:id*", beego.BeforeRouter, filters.AuthFilterFunc)
	beego.Run()
}
